<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <div>
        <!-- 搜索 -->
        <el-date-picker v-model="query.bisZhsqJbsj" type="month" value-format="yyyy-MM" format="yyyy-MM" placeholder="经办月份" style="width: 170px;" class="filter-item" @blur.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
        <el-button
          :loading="crud.downloadLoading"
          :disabled="!crud.data.length"
          class="filter-item"
          size="mini"
          type="warning"
          icon="el-icon-download"
          @click="crud.doExport"
        >导出</el-button>
      </div>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="660px">
        <el-form ref="form" :inline="true" :model="form" size="small" label-width="110px">
          <el-form-item label="姓名" prop="bisZhsqSnryXm">
            <el-input v-model="form.bisZhsqSnryXm" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="身份证" prop="bisZhsqSnrySfz">
            <el-input v-model="form.bisZhsqSnrySfz" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="性别" prop="bisZhsqSnryXb">
            <el-input v-model="form.bisZhsqSnryXb" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="年龄" prop="bisZhsqNl">
            <el-input v-model="form.bisZhsqNl" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="医保卡号" prop="bisZhsqYbkh">
            <el-input v-model="form.bisZhsqYbkh" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="参保状态" prop="bisZhsqCbzt">
            <el-input v-model="form.bisZhsqCbzt" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="待遇开始日期" prop="bisZhsqDykkrq">
            <el-input v-model="form.bisZhsqDykkrq" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="待遇结束日期" prop="bisZhsqDyjsrq">
            <el-input v-model="form.bisZhsqDyjsrq" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="医保所属区县" prop="bisZhsqSnryYbssqxCode">
            <el-select v-model="form.bisZhsqSnryYbssqxCode" disabled filterable placeholder="请选择" style="width: 170px;">
              <el-option
                v-for="item in dict.ccstcqh"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="ADL量表评分" prop="bisZhsqAdl">
            <el-input v-model="form.bisZhsqAdl" disabled style="width: 170px;">
              <el-button id="pipBtn" slot="append" icon="el-icon-document" title="测量ADL量表" @click="getAdl" />
            </el-input>
          </el-form-item>
          <el-form-item label="申请类别" prop="bisZhsqSqlb">
            <el-select v-model="form.bisZhsqSqlb" filterable placeholder="请选择" disabled style="width: 170px;">
              <el-option
                v-for="item in dict.sqlb"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="申请原因">
            <el-input v-model="form.bisZhsqSqyy" disabled :rows="3" type="textarea" style="width: 470px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="doSave()">通 过</el-button>
          <el-button :loading="crud.status.cu === 2" type="danger" @click="doOpenCy()">存 疑</el-button>
        </div>
      </el-dialog>
      <el-dialog title="意见" :visible.sync="dialogCyFormVisible" width="500px">
        <el-form>
          <el-form-item label="存疑原因">
            <el-input v-model="form.vbhyy" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogCyFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="doCy()">确 定</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column align="center" prop="bisZhsqZt" label="申请状态" width="70">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bisZhsqZt === '05'" effect="plain" type="">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
            <el-tag v-else-if="scope.row.bisZhsqZt === '00'" effect="plain" type="warning">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
            <el-tag v-else effect="plain" type="danger">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="lrsj" label="申请时间" width="150" />
        <el-table-column align="center" prop="bisZhsqYbkh" label="医保卡号" width="90" />
        <el-table-column align="center" prop="bisZhsqSnryXm" label="姓名" width="70" />
        <el-table-column align="center" prop="bisZhsqSnryXb" label="性别" width="50" />
        <el-table-column align="center" prop="bisZhsqSnrySfz" label="身份证" width="150" />
        <el-table-column align="center" prop="bisZhsqCblx" label="参保类型" width="90" />
        <el-table-column align="center" prop="bisZhsqNl" label="年龄" width="50" />
        <el-table-column align="center" prop="bisZhsqDykkrq" label="待遇开始日期" width="100" />
        <el-table-column align="center" prop="bisZhsqDyjsrq" label="待遇结束日期" width="100" />
        <el-table-column align="center" prop="bisZhsqSndj" label="失能等级" />
        <el-table-column align="center" prop="bisZhsqAdl" label="评分" width="50" />
        <el-table-column align="center" prop="bisZhsqSnryYbssqxName" label="统筹区" width="90" />
        <el-table-column align="left" header-align="center" prop="bisSbgsQymc" label="商保机构" width="250" />
        <el-table-column align="center" prop="bisZhsqHljgBm" label="定点编码" width="90" />
        <el-table-column align="left" header-align="center" prop="bisHljgQymc" label="护理机构" width="250" />
        <el-table-column align="center" prop="bisZhsqJbrxm" label="经办人" width="100" />
        <el-table-column align="center" prop="bisZhsqJbsj" label="经办日期" width="100" />
        <el-table-column align="center" prop="bisZhsqCyzt" label="经办状态" width="100">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bisZhsqCyzt === '60'" effect="plain" type="">
              {{ dict.label.zhzt[scope.row.bisZhsqCyzt] }}
            </el-tag>
            <el-tag v-else effect="plain" type="danger">
              {{ dict.label.zhzt[scope.row.bisZhsqCyzt] }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudZhsqCy from '@/api/business/zhsqCy'
import crudZhsq from '@/api/business/zhsq'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisZhsqId: null, bisZhsqHljgId: null, bisZhsqSnryId: null, bisZhsqSnryXm: null, bisZhsqSnryXb: null, bisZhsqSnrySfz: null, bisZhsqSnryYbssqx: null, bisZhsqDykkrq: null, bisZhsqDyjsrq: null, bisZhsqXsdyq: null, bisZhsqAdl: null, bisZhsqZt: null, ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, sfyx: null, bz: null, bisZhsqAdlPc: null, bisZhsqSndj: null, bisZhsqRybh: null, bisZhsqNl: null, bisZhsqLxdh: null, bisZhsqHldzSsqx: null, bisZhsqHldzXxdz: null, bisZhsqHldz: null, bisZhsqJhrxm: null, bisZhsqJhrdh: null, bisZhsqGx: null, bisZhsqSqyy: null, bisZhsqYbkh: null, bisZhsqCbzt: null, bisUserId: null, bisSbgsId: null, bisZhsqGrbh: null, bisPggsId: null, bisZhsqZhlb: null, bisZhsqHljgBm: null, bisZhsqCblx: null, bisZhsqSqlb: null, bisZhsqTjsj: null, bisZhsqJbr: null, bisZhsqJbrxm: null, bisZhsqCyzt: null, bisZhsqJbsj: null }
export default {
  name: 'ZhsqCy',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['xb', 'yjsgx', 'ccs', 'zhzt', 'ccstcqh', 'sqlb'],
  cruds() {
    return CRUD({ title: '照护存疑', url: 'api/zhsqCy/queryAllCqCy', idField: 'bisZhsqId', sort: 'bisZhsqId,desc', crudMethod: { ...crudZhsqCy }})
  },
  data() {
    return {
      dialogCyFormVisible: false,
      permission: {
        add: ['admin', 'zhsqCy:add'],
        edit: ['admin', 'zhsqCy:edit'],
        del: ['admin', 'zhsqCy:del']
      },
      rules: {
        bisZhsqId: [
          { required: true, message: '居家照护申请ID不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    handleClick(obj) {
      console.log(obj)
      this.crud.toEdit(obj)
    },
    /**
     * 弹出退回页面
     * @param zt
     */
    doOpenCy() {
      this.dialogCyFormVisible = true
    },
    /**
     * 自定义保存
     * @param zt
     */
    doSave(zt) {
      this.form.bisZhsqZt = '60'
      this.crud.status.edit = CRUD.STATUS.PROCESSING
      crudZhsq.checkPgPcjgzh(this.form)
        .then(res => {
          this.crud.status.edit = CRUD.STATUS.NORMAL
          this.$notify({
            title: '抽取通过',
            type: 'success',
            duration: 2500
          })
          this.crud.toQuery()
        })
        .catch(err => {
          this.crud.status.edit = CRUD.STATUS.PREPARED
          console.log(err)
        })
    },
    /**
     * 存疑
     * @param zt
     */
    doCy() {
      if (this.form.vbhyy === undefined) {
        this.$notify({
          title: '请填写存疑原因',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.$confirm('你确定存疑吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.form.bisZhsqZt = '61'
        this.form.bz = this.form.vbhyy
        this.crud.status.edit = CRUD.STATUS.PROCESSING
        crudZhsq.checkPgPcjgzh(this.form)
          .then(res => {
            this.crud.status.edit = CRUD.STATUS.NORMAL
            this.$notify({
              title: '操作成功',
              type: 'success',
              duration: 2500
            })
            this.dialogCyFormVisible = false
            this.crud.toQuery()
          })
          .catch(err => {
            this.crud.status.edit = CRUD.STATUS.PREPARED
            console.log(err)
          })
      })
    }
  }
}
</script>

<style scoped>

</style>
